package com.example.app3.ui.notifications;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.app3.R;

import com.example.app3.login.RegisterActivity;
import com.example.app3.ui.notifications.recylerView.NumbersAdapter;
import com.example.app3.ui.notifications.recylerView.domain.RandomNumbers;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class NotificationsFragment extends Fragment {

    private EditText startId;
    private EditText endId;
    private EditText numberId;
    private Button doId;
    private List list = new ArrayList<RandomNumbers>();

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {

        View root = inflater.inflate(R.layout.fragment_notifications, container, false);


        startId = root.findViewById(R.id.editText7);
        endId = root.findViewById(R.id.editText6);
        numberId = root.findViewById(R.id.editText5);
        doId = root.findViewById(R.id.button30);


        doId.setOnClickListener(v -> {
            if(startId.getText().toString().isEmpty()||endId.getText().toString().isEmpty()||numberId.getText().toString().isEmpty()){
                Toast.makeText(this.getActivity(), "请输入完所有的数据", Toast.LENGTH_SHORT).show();
                return;
            }
            int start = Integer.valueOf(startId.getText().toString());
            int end = Integer.valueOf(endId.getText().toString());
            int number = Integer.valueOf(numberId.getText().toString());
            //大小判断
             if(start>end){
                 int tmp=end;
                 end=start;
                 start=tmp;
             }
            Random r = new Random();


            //一行两个
            for (int i = 0; i < number / 2; i++) {
                int value1 = r.nextInt(end - start + 1) + start;
                int value2 = r.nextInt(end - start + 1) + start;
                list.add(new RandomNumbers(value1+"", value2+""));

            }
            if (number % 2 != 0) {
                list.add(new RandomNumbers((r.nextInt(end - start + 1) + start)+"", ""));
            }

            RecyclerView recyclerView = root.findViewById(R.id.recyclerview2);
            LinearLayoutManager layoutManager = new LinearLayoutManager(this.getActivity());
            recyclerView.setLayoutManager(layoutManager);
            NumbersAdapter adapter = new NumbersAdapter(list);
            recyclerView.setAdapter(adapter);


        });
        return root;
    }


}